package com.bckj.fastboot.iot.parse.mq.consumer;

import com.bckj.fastboot.iot.common.dto.msg.IotProtocolDataMessage;
import com.bckj.fastboot.iot.common.mq.consumer.IotProtocolDataMessageConsumer;
import com.bckj.fastboot.iot.parse.core.StandardProtocolParser;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

import com.bckj.fastboot.iot.common.constant.IotMQConstants;

/**
 * IotProtocolMessageConsumerImpl
 *
 * @author wfc
 **/
@Slf4j
@Component
public class IotProtocolDataMessageConsumerImpl implements IotProtocolDataMessageConsumer {

    @Resource
    private StandardProtocolParser standardProtocolParser;

    @Override
    public void onMessage(IotProtocolDataMessage message) {
        switch (message.getTag()) {
            case IotMQConstants.IOT_PROTOCOL_DATA_MATT_TAG -> {
                log.info("收到mqtt协议数据:{}", message);
                standardProtocolParser.parse(message.getPayload().getBytes(StandardCharsets.UTF_8), message.getDevCode());
            }
        }
    }
}
